package com.itheima.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.itheima.tanhua.api.PersonalityApi;
import com.itheima.tanhua.domain.Personality;
import com.itheima.tanhua.domain.Score;
import com.itheima.tanhua.dubbo.mappers.PersonalityMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author Lff
 * @date 2022/4/9
 */
@DubboService
public class PersonalityApiImpl implements PersonalityApi {
    @Autowired
    private PersonalityMapper personalityMapper;


    /**
     * 根据问卷难度
     * 用户成绩来获取指定结果
     *
     * @param level
     * @param stars
     * @param score
     * @return
     */
    @Override
    public Personality findPersonality(Integer level, Integer stars, Integer score) {
        LambdaQueryWrapper<Personality> qw = Wrappers.lambdaQuery(Personality.class);
        qw.eq(Personality::getLevel, level)
                .eq(Personality::getStars, stars)
                .eq(Personality::getSection, score);
        return personalityMapper.selectOne(qw);
    }

    /**
     * 通过id查询记录
     *
     * @param id
     * @return
     */
    @Override
    public Personality findById(Long id) {
        return personalityMapper.selectById(id);
    }
}
